Add write support to bushnell_trl.
authorrobertl <robertl>
Wed, 23 Dec 2009 16:42:34 +0000 (16:42 +0000)
committerrobertl <robertl>
Wed, 23 Dec 2009 16:42:34 +0000 (16:42 +0000)
bushnell_trl.c
xmldoc/formats/bushnell_trl.xml

index 7b6dd852a8a28a1cf7929844ba4257f440ede9e8..e7d85a720e5750df4824e469b294e85665392db2 100644 (file)
@@ -24,6 +24,8 @@
 #define MYNAME "Bushnell Trail"
 
 static gbfile *file_in;
+static gbfile *file_out;
+static int trkpt_count;
 static route_head* trk_head;
 
 static
@@ -45,7 +47,30 @@ rd_init(const char *fname) {
 
 static void
 rd_deinit(void) {
-  gbfclose(file_in);
+  gbfclose(file_out);
+}
+
+static void
+wr_init(const char *fname) {
+  file_out = gbfopen_le(fname, "w", MYNAME);
+  trkpt_count = 0;
+  static char obuf[20] = {"TL003"};
+  gbfwrite(&obuf, 1, 20, file_out);
+}
+
+static void
+wr_deinit(void) {
+  int i = trkpt_count;
+  while (i < 4502) {
+    gbfputint32(0, file_out);
+    gbfputint32(0, file_out);
+    i++;
+  }
+  gbfputint32(0, file_out);
+  gbfputint16(trkpt_count, file_out);
+  gbfputc(1, file_out);
+
+  gbfclose(file_out);
 }
 
 /*
@@ -72,16 +97,32 @@ bushnell_read(void) {
   }
 }
 
+static void
+bushnell_write_one(const waypoint *wpt) {
+  trkpt_count++;
+  if (trkpt_count > 4502)
+    fatal(MYNAME " too many trackpoints.  Max is 4502.");
+
+  gbint32 lat = wpt->latitude  * 10000000.0;
+  gbint32 lon = wpt->longitude * 10000000.0;
+  gbfputint32(lat, file_out);
+  gbfputint32(lon, file_out);
+}
+
+static void
+bushnell_write(void) {
+  track_disp_all(NULL, NULL, bushnell_write_one);
+}
 
 ff_vecs_t bushnell_trl_vecs = {
   ff_type_file,
-  { ff_cap_none, ff_cap_read, ff_cap_none },
+  { ff_cap_none, ff_cap_read | ff_cap_write, ff_cap_none },
   rd_init,
-  NULL,
+  wr_init,
   rd_deinit,
-  NULL,
+  wr_deinit,
   bushnell_read,
-  NULL,
+  bushnell_write,
   NULL,
   bushnell_args,
   CET_CHARSET_MS_ANSI, 0  /* Not really sure... */
index 34059bed55956d851e72c7113b0891b67ed1c21f..0a17cac7e5ac47f5e61586482c5deeb30bd7d8e8 100644 (file)
@@ -1,11 +1,15 @@
 <para>
-This format supports reading tracks from 
+This format supports tracks from 
 <ulink url="http://www.bushnell.com/products/gps/">Bushnell GPS</ulink> 
 receivers, notably the <productname>Onix 400</productname>.
 </para>
 <para>
 This format reads individual .trl files as written by the GPS.  As this is
 a reverse-engineered format, it's not understood how long tracks, in 
-particular, spam multiple files so initially this format is most effective
-on tracks under a few thousand points.  
+particular, span multiple files so initially this format is most effective
+on tracks under a few thousand points.
+</para>
+<para>
+  When writing tracks, a maximum of 4502 points is supported as this is the
+  most we believe these units can represent in a track.
 </para>